/*
  ID:ningyusui
  PROG:shopping
  LANG:C++
*/
#  include<iostream>
#  include<cstring>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct
{
        int  sum,itemCount[1002];
}offers[108];
struct
{
        int  limit,itemId,price;
}orders[7];
int  n,m,f[6][6][6][6][6];
void  input()
{
      freopen("shopping.in","r",stdin);
      freopen("shopping.out","w",stdout);
      int  i,j,num,l;
      scanf("%d",&n);
      for  (i=1;i<=n;i++)
      {
           scanf("%d",&num);
           for  (j=1;j<=num;j++)
           {
                scanf("%d",&l);
                scanf("%d",&offers[i].itemCount[l]);
           }
           scanf("%d",&offers[i].sum);
      }
      scanf("%d",&m);
      for  (i=1;i<=m;i++)
      {
           scanf("%d%d%d",&orders[i].itemId,&orders[i].limit,&offers[++n].sum);
           offers[n].itemCount[orders[i].itemId]=1;
      }
}
void  work()
{
      memset(f,50,sizeof(f));
      f[0][0][0][0][0]=0;
      int i,b1,b2,b3,b4,b5,m1,m2,m3,m4,m5;
      for  (i=1;i<=n;i++)
      {
            m1=offers[i].itemCount[orders[1].itemId];
            m2=offers[i].itemCount[orders[2].itemId];
            m3=offers[i].itemCount[orders[3].itemId];
            m4=offers[i].itemCount[orders[4].itemId];
            m5=offers[i].itemCount[orders[5].itemId];
            for  (b1=m1;b1<=orders[1].limit;b1++)
               for  (b2=m2;b2<=orders[2].limit;b2++)
                 for  (b3=m3;b3<=orders[3].limit;b3++)
                   for  (b4=m4;b4<=orders[4].limit;b4++)
                     for  (b5=m5;b5<=orders[5].limit;b5++)
                          f[b1][b2][b3][b4][b5]=min(f[b1][b2][b3][b4][b5],f[b1-m1][b2-m2][b3-m3][b4-m4][b5-m5]+offers[i].sum);
      }
}
void  output()
{
      printf("%d\n",f[orders[1].limit][orders[2].limit][orders[3].limit][orders[4].limit][orders[5].limit]);
      fclose(stdin);
      fclose(stdout);
}
int  main()
{
     input();
     work();
     output();
     return 0;
}
